package xyz.comfyz.web.commons.framework.result;


/**
 * @author :    comfy
 * @date :      2018-05-07 14:59:29
 * @since :     1.8
 * <p>
 * 异常
 */
public class ExpectedExeption extends RuntimeException {

    private final Code code;

    private final String msg;

    public ExpectedExeption(Code code) {
        super(code.getMessage());
        this.code = code;
        this.msg = code.getMessage();
    }

    public ExpectedExeption(Code code, String msg) {
        super(msg);
        this.code = code;
        this.msg = msg;
    }

    public ExpectedExeption(Code code, Throwable e) {
        super(code.getMessage(), e);
        this.code = code;
        this.msg = e.getMessage();
    }

    public ExpectedExeption(Code code, String msg, Throwable e) {
        super(code.getMessage(), e);
        this.code = code;
        this.msg = msg;
    }


    public Code getCode() {
        return code;
    }

    public ErrorMessage getErrorMessage() {
        return new SimpleErrorMessage(code.getCode(), msg);
    }
}
